package com.test;

import com.cnsugar.common.utils.DateUtils;
import lombok.Data;

/**
 * @Description 位置上报消息体
 * @Author Sugar
 * @Date 2020/9/28 11:15
 */
@Data
public class LocationBody {

    private AlarmProps alarm;

    private StateProps state;

    private String railNo;

    private int offset;

    private int speed;

    private long captureTime; //数据采集时间

    private String wayId;

    private ExtraInfo extraInfo;

    private long onTime = System.currentTimeMillis() / 1000; //通信端接收时间

    @Override
    public String toString() {
        return "{" +
                "railNo=" + railNo +
                ", offset=" + offset +
                ", speed=" + speed +
                ", time=" + DateUtils.formatTimestamp(captureTime) +
                ", alarm=" + alarm +
                ", state=" + state +
                ", wayId=" + wayId +
                ", extras=" + extraInfo +
                "}";
    }

    /**
     * 报警标识
     */
    @Data
    public static class AlarmProps {
        private int code;
        private String desc; //报警描述

        @Override
        public String toString() {
            return "" + code + (code != 0 ? "(" + desc + ")" : "");
        }
    }

    /**
     * 运行状态
     */
    @Data
    public static class StateProps {
        //注意：字段的顺序必须与协议中保持一致，否则需要手动指定index
        private int mode;

        private int status;

        private int track;

        private int drive;

        private int gear;

        private int load;

        private int door;

        @Override
        public String toString() {
            return "{" +
                    "mode=" + mode +
                    ", status=" + status +
                    ", track=" + track +
                    ", drive=" + drive +
                    ", gear=" + gear +
                    ", load=" + load +
                    ", door=" + door +
                    '}';
        }
    }

    /**
     * 附加信息项
     */
    @Data
    public static class ExtraInfo {
        private Integer f0x00;

        private Integer f0x01;

        private Integer f0x02;

        private Integer f0x03;

        private Integer f0x04;

        private Integer f0x05;

        private Integer f0x06;

//        private Integer f0x07;//前轮保留
//        private Integer f0x08;//前轮保留

        private Integer f0x09;

        private Integer f0x0A;

        private Integer f0x0B;

        private Integer f0x0C;

        private Integer f0x0D;

//        private int f0x0E;//后轮保留
//        private int f0x0F;//后轮保留

        private Integer f0x10;

        private Integer f0x11;

        private Integer f0x12;

        private String f0x13;

        private Integer f0x14;

        private String f0x15;

        private Integer f0x16;

        private Integer f0x17;

        private Integer f0x18;

        @Override
        public String toString() {
            return "{" +
                    (f0x00 == null ? "" : "0x00=" + f0x00 + ", ") +
                    (f0x01 == null ? "" : "0x01=" + f0x01 + ", ") +
                    (f0x02 == null ? "" : "0x02=" + f0x02 + ", ") +
                    (f0x03 == null ? "" : "0x03=" + f0x03 + ", ") +
                    (f0x04 == null ? "" : "0x04=" + f0x04 + ", ") +
                    (f0x05 == null ? "" : "0x05=" + f0x05 + ", ") +
                    (f0x06 == null ? "" : "0x06=" + f0x06 + ", ") +
                    (f0x09 == null ? "" : "0x09=" + f0x09 + ", ") +
                    (f0x0A == null ? "" : "0x0A=" + f0x0A + ", ") +
                    (f0x0B == null ? "" : "0x0B=" + f0x0B + ", ") +
                    (f0x0C == null ? "" : "0x0C=" + f0x0C + ", ") +
                    (f0x0D == null ? "" : "0x0D=" + f0x0D + ", ") +
                    (f0x10 == null ? "" : "0x10=" + f0x10 + ", ") +
                    (f0x11 == null ? "" : "0x11=" + f0x11 + ", ") +
                    (f0x12 == null ? "" : "0x12=" + f0x12 + ", ") +
                    (f0x13 == null ? "" : "0x13=" + f0x13 + ", ") +
                    (f0x14 == null ? "" : "0x14=" + f0x14 + ", ") +
                    (f0x15 == null ? "" : "0x15=" + f0x15 + ", ") +
                    (f0x16 == null ? "" : "0x16=" + f0x16 + ", ") +
                    (f0x17 == null ? "" : "0x17=" + f0x17 + ", ") +
                    (f0x18 == null ? "" : "0x18=" + f0x18) +
                    "}";
        }
    }
}
